using System;
using System.Configuration;
using System.Text;

namespace VatLid
{
	/// <summary>
	/// Provides method to retrieve connection string from web.config
	/// and decyrpt the string using DataProtector class. 
	/// </summary>
	public class SecureConnection
	{
		static public string GetCnxString(string configKey)
		{
			string strCnx;
			string strEncryptedCnx = ConfigurationSettings.AppSettings[configKey];
			strCnx=strEncryptedCnx;
//			try
//			{
//				DataProtector dp = new DataProtector(DataProtector.Store.USE_MACHINE_STORE);				
//				byte[] dataToDecrypt = Convert.FromBase64String(strEncryptedCnx);
//				strCnx = Encoding.UTF8.GetString(dp.Decrypt(dataToDecrypt,null));
//			}
//			catch
//			{
//				strCnx=strEncryptedCnx.Substring(0,9) + strEncryptedCnx.Substring(14,strEncryptedCnx.Length-14) ;
//				//"Password=Kaze_sa123;User ID=sa;Initial Catalog=leadership;Data Source=10.4.4.4";
//
//			}
			return strCnx;
		}
	}
}
